<template>
  <a-layout id="components-layout-demo-top-side-2">
    <a-layout-header class="header">
      <div class="logo" />
      <a-menu
        theme="dark"
        mode="horizontal"
        :default-selected-keys="['2']"
        :style="{ lineHeight: '64px' }"
      >
        <a-menu-item key="1"> 导航1 </a-menu-item>
        <a-menu-item key="2"> 导航 2 </a-menu-item>
        <a-menu-item key="3"> 导航 3 </a-menu-item>
      </a-menu>
    </a-layout-header>
    <a-layout>
      <a-layout-sider width="200" style="background: #fff">
        <a-menu
          mode="inline"
          :default-selected-keys="['1']"
          :style="{ height: '100%', borderRight: 0 }"
          @select="menuchange"
        >
          <a-sub-menu :key="item.id" v-for="(item, index) in menusList">
            <span slot="title"
              ><a-icon :type="menusIcon[index].icon" />{{ item.authName }}</span
            >
            <a-menu-item
              :key="item_cd.id"
              v-for="item_cd in item.children"
              >{{ item_cd.authName }}
            </a-menu-item>
          </a-sub-menu>
        </a-menu>
      </a-layout-sider>
      <a-layout style="padding: 0 24px 24px">
        <a-breadcrumb style="margin: 16px 0">
          <a-breadcrumb-item>Home</a-breadcrumb-item>
          <a-breadcrumb-item>List</a-breadcrumb-item>
          <a-breadcrumb-item>App</a-breadcrumb-item>
        </a-breadcrumb>
        <a-layout-content
          :style="{
            background: '#fff',
            padding: '24px',
            margin: 0,
            minHeight: '280px',
          }"
        >
          <router-view></router-view>
        </a-layout-content>
      </a-layout>
    </a-layout>
  </a-layout>
</template>
<script>
export default {
  data() {
    return {
      collapsed: false,
      menusList: [],
      menusIcon: [
        { id: "125", icon: "form" },
        { id: "103", icon: "snippets" },
        { id: "101", icon: "account-book" },
        { id: "102", icon: "database" },
        { id: "145", icon: "hourglass" },
      ],
    };
  },
  created() {
    this.getMenus();
  },
  methods: {
    async getMenus() {
      const { data: res } = await this.$http.get("menus");
      console.log(res);
      if (res.meta.status !== 200) {
        this.$message.info("获取用户菜单失败");
      }
      this.menusList = res.data;
    },
    menuchange(event) {
      console.log(event);
    },
  },
};
</script>

<style>
#components-layout-demo-top-side-2 .logo {
  width: 120px;
  height: 31px;
  background: rgba(255, 255, 255, 0.2);
  margin: 16px 28px 16px 0;
  float: left;
}
.ant-layout .ant-layout-has-sider {
  min-height: calc(100vh - 64px);
  box-sizing: border-box;
}
</style>
